package com.compass.doctor.ui.home

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.compass.doctor.R
import com.compass.doctor.base.BaseVBActivity
import com.compass.doctor.callback.OnChatMenuClick
import com.compass.doctor.databinding.ActivityDoctorChatBinding
import com.compass.doctor.ui.chat.util.CustomUIConfig
import com.compass.doctor.ui.setting.ReportActivity
import com.compass.framework.constant.CHAT_INFO
import com.netease.yunxin.kit.chatkit.ui.`fun`.page.fragment.FunChatP2PFragment
import com.netease.yunxin.kit.chatkit.ui.view.input.ActionConstants
import com.netease.yunxin.kit.corekit.im.model.UserInfo
import com.netease.yunxin.kit.corekit.im.utils.RouterConstant

/**
 * Description： 医生聊天界面
 * Date:2024/1/18 14:06
 */
class DoctorChatActivity : BaseVBActivity<ActivityDoctorChatBinding>() {

    companion object {
        fun start(context: Context, userInfo: UserInfo) {
            val intent = Intent(context, DoctorChatActivity::class.java)
            intent.putExtra(CHAT_INFO, userInfo)
            context.startActivity(intent)
        }
    }

    private lateinit var chatFragment: FunChatP2PFragment//单聊Fragment
    private lateinit var userInfo: UserInfo//云信信息

    private var onChatMenuClick: OnChatMenuClick = object : OnChatMenuClick {
        override fun onMenuCallBack(action: String) {
            onCustomItemClick(action)
        }
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        chatFragment.onNewIntent(intent)
    }

    override fun initView(savedInstanceState: Bundle?) {
        //这里调用时为了处理长时间注入后台 配置信息被回收问题（主要出现在华为mate60上）
        userInfo = intent.serializable(CHAT_INFO)!!
        mBinding.tvTitleBar.setMiddleText(userInfo.getUserInfoName())
        CustomUIConfig.initChatMoreMenu(
            isDoctorIM = true,//医生对医生不展示扩展菜单
            isInquiry = false,
            ifReturnVisit="1",
            onChatMenuClick = onChatMenuClick
        )
        CustomUIConfig.initChatBottomAndTopLayout(
            isPatient = false,
            isInquiry = false,
            onChatBottomClick = null,
            onIExpressionButtonClickListener = null
        )
        //set fragment
        chatFragment = FunChatP2PFragment()
        val bundle = Bundle()
        bundle.putSerializable(RouterConstant.CHAT_KRY, userInfo)
        chatFragment.arguments = bundle

        val fragmentManager = supportFragmentManager
        fragmentManager.beginTransaction().add(R.id.container, chatFragment)
            .commitAllowingStateLoss()

    }

    override fun initData() {

    }


    /**
     * 菜单按钮点击 方法 待定是否写在这里
     */
    private fun onCustomItemClick(action: String) {
        when (action) {
            //举报消息
            ActionConstants.CUSTOM_ACTION_TYPE_REPORT -> {
                //举报
                ReportActivity.start(this)
            }
        }
    }

}